const { mongoose, db } = require('../utils/mongoose')

let schema = mongoose.Schema({
    id:{type:String,required:true},
    username:{type:String,required:true},
    password:{type:String,required:true},
    // sex:{type:String,required:true},
    // lifestage:{type:String,required:true},
    // nickname:{type:String,required:false},
    // phone:{type:String,required:false},
    // email:{type:String,required:true},
    // avatar:{type:String,required:false},
})

let Collection = mongoose.model('users', schema)

//注册
const register = (data) => {
    let model = new Collection(data)
    return model.save()
        .then(res => res)
        .catch(err => {
            return err;
        })
}

//查找
const getUsers=(query={},page={skip:0,limit:0})=>{
    return Collection.find(query).limit(page.limit).skip(page.skip)
        .then(res=>res)
        .catch(err=>{
            console.log(err);
            return false;
        })
}
//更新
const updateUserInfo=(query,updated)=>{
    return Collection.updateOne(query,updated)
        .then(res=>res)
        .catch(err=>{
            console.log(err);
            return false;
        })
}
module.exports={
    register,
    getUsers
    // updateUserInfo
}